package com.uco.thread;

public class Create02 {
    public static void main(String[] args) {

        Thread mt1 = new Thread(new MyThread1());
        mt1.start();

        // runnable接口的简化版本，使用匿名内部类，结合lambda表达式，更加简洁
        Thread mt11 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println("MyThread11 thread is running :" + i);
            }
        }
        );
        mt11.start();

        for (int i = 0; i < 10; i++) {
            System.out.println("main thread is running :" + i);
        }

    }
}

// 创建线程的方法二：实现Runnable接口
// 优点：实现Runnable接口，实现run()方法，代码简单，且通过实现接口实现，类功能可以更强大
class MyThread1 implements Runnable {
    @Override
    public void run()
    {
        for (int i = 0; i < 10 ; i++) {
            System.out.println("MyThread1 is running :" + i );
        }
    }
}